﻿<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head lang="en">
    <meta charset="UTF-8">
    <title>注册</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>

    <link rel="stylesheet"
          href="../AmazeUI-2.4.2/assets/css/amazeui.min.css"/>
    <link href="../css/dlstyle.css" rel="stylesheet" type="text/css">
    <script src="../AmazeUI-2.4.2/assets/js/jquery.min.js"></script>
    <script src="../AmazeUI-2.4.2/assets/js/amazeui.min.js"></script>
    <script src="../HT/assets/layer/layer.js" type="text/javascript"></script>
    <style type="text/css">

        input {
            border: 0;
            outline: none;
            background-color: rgba(0, 0, 0, 0);
        }

    </style>
</head>

<body>

<div class="login-boxtitle">
    <a href="home/demo.html"><img alt="" src="../images/logobig.png"/></a>
</div>

<div class="res-banner">
    <div class="res-main">
        <div class="login-banner-bg">
            <span></span><img src="../images/big.jpg"/>
        </div>
        <div class="login-box">

            <div class="am-tabs" id="doc-my-tabs">
                <ul class="am-tabs-nav am-nav am-nav-tabs am-nav-justify">
                    <li class="am-active"><a href="">邮箱注册</a></li>
                </ul>
                <div class="am-tabs-bd">
                    <div class="am-tab-panel am-active">
                        <form method="post">
                            <div class="user-phone">
                                <label for="phone">
                                    <i class="am-icon-envelope-o" style="margin-top: 12px"></i></label> <input
                                    type="tel"
                                    name="" id="phone" placeholder="请输入邮箱">
                            </div>
                            <div class="verification">
                                <label for="code"><i class="am-icon-code-fork" style="margin-top: 12px"></i></label>
                                <input
                                        type="tel" name="" id="code" placeholder="请输入验证码"> <a
                                    class="btn"  id="sendMobileCode"> <span
                                    id="dyMobileButton">获取</span></a>
                            </div>
                            <div class="user-pass">
                                <label for="password"><i class="am-icon-lock" style="margin-top: 12px"></i></label>
                                <input
                                        type="password" name="" id="password" placeholder="设置密码">
                            </div>
                            <div class="user-pass">
                                <label for="passwordRepeat"><i class="am-icon-lock"
                                                               style="margin-top: 12px"></i></label>
                                <input type="password" name="" id="passwordRepeat"
                                       placeholder="确认密码">
                            </div>
                        </form>
                        <div class="login-links">
                            <a href="login.html" class="am-fr" style="color: #0000ff">返回登录</a>
                            <br>
                            <br>
                            <label for="reader-me"> <input id="reader-me"
                                                           type="checkbox"> 点击表示您同意商城《服务协议》
                            </label>

                        </div>
                        <div class="am-cf">
                            <input type="button" name="" value="注册"
                                   class="am-btn am-btn-primary am-btn-sm am-fl commit-button ">
                        </div>

                        <hr>
                    </div>
                </div>
            </div>

        </div>
    </div>

    <div class="footer ">
        <div class="footer-hd ">
            <p style="text-align: center;">
                <b>|</b> <a href="# ">商城首页</a> <b>|</b> <a href="# ">支付宝</a> <b>|</b>
                <a href="# ">物流</a>
            </p>
        </div>
        <div class="footer-bd ">
            <p>

                <a href="# ">合作伙伴</a> <a href="# ">联系我们</a> <a href="# ">网站地图</a> <em
                    style="text-align: center;">© 2015-2025 zking 版权所有</em>
            </p>
        </div>
    </div>
</div>
<script type="text/javascript">

    //点击获取验证码按钮
    var reg = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
    var count = 10;
    function changeText(){
        if(count==0){
            //去掉定时器的方法
            window.clearInterval(t1);
            $("#dyMobileButton").text("获取");
            return
        }
        count -= 1;
        $("#dyMobileButton").text(count+"秒");
    }

    var mail_code="";
    var t1;
    //点击提交按钮
    $("#dyMobileButton").click(function (){
        if($("#dyMobileButton").text()!="获取"){
            return
        }
        if($("#phone").val().length==0){
            layer.msg('请填写邮箱!', {icon: 1, time: 1500});
            return;
        }
        if(!(reg.test($("#phone").val()))){
            layer.msg('邮箱格式错误!', {icon: 1, time: 1500});
            $("#phone").val("");
            return;
        }
        //获取验证码
        $.ajax({
            url: "http://localhost:8080/SnacksShop/user.do?type=getMailCode",
            crossDomain: true,
            data:{
                mail:$("#phone").val(),
                value:"register"
            },
            xhrFields: {
                withCredentials: true
            },
            type: "post",
            success: function (data) {
                if(data=="exist"){
                    layer.msg('该邮箱已存在!', {icon: 1, time: 1500});
                    $("#phone").val();
                    return ;
                }else{
                    t1 =  window.setInterval("changeText()",1000);
                }
            },
            error: function (data) {
                layer.msg('请检查你的网络!', {icon: 1, time: 1500});
            }
        })

    })


    $(".commit-button").click(function (){
        if($("#phone").val().length==0 || $("#code").val().length==0 || $("#password").val().length==0 || $("#passwordRepeat").val().length==0 ){
            layer.msg('请填写必要信息!', {icon: 1, time: 1500});
            return;

        }
        //验证邮箱格式
        if(!(reg.test($("#phone").val()))){
            layer.msg('邮箱格式错误!', {icon: 1, time: 1500});
            $("#phone").val("");
            return;
        }

        //验证密码
        if($("#password").val().length<6){
            layer.msg('密码必须大于6位!', {icon: 1, time: 1500});
            $("#password").val("");
            return ;
        }
        //验证两次密码是否一致
        if($("#password").val()!=$("#passwordRepeat").val()){
            layer.msg('两次密码不一致!', {icon: 1, time: 1500});
            $("#password").val("");
            $("#passwordRepeat").val("");
            return ;
        }

        if(!$("#reader-me").prop("checked")){
            layer.msg('请勾选同意单选框!', {icon: 1, time: 1500});
            return ;
        }
        //执行修改密码操作
        $.ajax({
            url: "http://localhost:8080/SnacksShop/user.do?type=register",
            crossDomain: true,
            data:{
                mail:$("#phone").val(),
                code:$("#code").val(),
                pass:$("#password").val(),
            },
            xhrFields: {
                withCredentials: true
            },
            type: "post",
            success: function (data) {
                if(data=="error"){
                    layer.msg('验证码错误!', {icon: 1, time: 1500});
                    $("#code").val("");
                    return ;
                }
                if(data == "true"){
                    layer.msg('注册成功，请登录!', {icon: 1, time: 1500});
                    location.href="./login.html";
                    return ;
                }
                if(data == "false"){
                    layer.msg('网络异常!', {icon: 1, time: 1500});
                    return ;
                }
            },
            error: function (data) {
                layer.msg('请检查你的网络!', {icon: 1, time: 1500});
            }
        })

    })
</script>
</body>

</html>